<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="12">
            <a-form-model-item label="数据日期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="sjrq">
              <j-date placeholder="请选择数据日期" v-model="model.sjrq"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="所属地人民银行机构名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ssdrmyhmc">
              <a-input v-model="model.ssdrmyhmc" placeholder="请输入所属地人民银行机构名称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="所属地人民银行机构金融机构编码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="sssrmyhjrjgbm">
              <a-input v-model="model.sssrmyhjrjgbm" placeholder="请输入所属地人民银行机构金融机构编码"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="所属地人民银行机构负责人姓名" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ssdrmyhjgfzrxm">
              <a-input v-model="model.ssdrmyhjgfzrxm" placeholder="请输入所属地人民银行机构负责人姓名"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="资金划出账户" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="zjhczh">
              <a-input v-model="model.zjhczh" placeholder="请输入资金划出账户"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="人民银行债权类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="rmyhzqlx">
              <j-tree-select
                ref="treeSelect"
                placeholder="请选择人民银行债权类型"
                v-model="model.rmyhzqlx"
                dict="llbb_param_config,name,code"
                pidValue="1486574204954914818"
                hasChildField="has_child"
              />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="资金划入账户" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="zjhrzh">
              <a-input v-model="model.zjhrzh" placeholder="请输入资金划入账户"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="机构名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="jgmc">
              <a-input v-model="model.jgmc" placeholder="请输入机构名称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="单位联系电话" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="dwlxdh">
              <a-input v-model="model.dwlxdh" placeholder="请输入单位联系电话"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="单位地址" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="dwdz">
              <a-input v-model="model.dwdz" placeholder="请输入单位地址"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="债权余额" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="zqye">
              <a-input-number v-model="model.zqye" placeholder="请输入债权余额" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="应付利息" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="yflx">
              <a-input-number v-model="model.yflx" placeholder="请输入应付利息" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="本息合计" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="bxhj">
              <a-input-number v-model="model.bxhj" placeholder="请输入本息合计" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="备注" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="bz">
              <a-input v-model="model.bz" placeholder="请输入备注"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="内部机构号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="nbjgh">
              <Mechanism v-model="model.nbjgh"></Mechanism>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'
  import Mechanism from '@/components/Mechanism'

  export default {
    name: 'CdCredrightsInfForm',
    components: {
      Mechanism
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model:{
         },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 8 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 13 },
        },
        confirmLoading: false,
        validatorRules: {
          sjrq: [
            { required: true, message: '请选择数据日期!'},
          ],
          ssdrmyhmc: [
            { required: true, message: '请输入所属地人民银行机构名称!'},
          ],
          zjhczh: [
            { required: true, message: '请输入资金划出账户!'},
          ],
          rmyhzqlx: [
            { required: true, message: '请选择人民银行债权类型!'},
          ],
          zjhrzh: [
            { required: true, message: '请输入资金划入账户!'},
          ],
          jgmc: [
            { required: true, message: '请输入机构名称!'},
          ],
          zqye: [
            { required: true, message: '请输入债权余额!'},
          ],
          yflx: [
            { required: true, message: '请输入应付利息!'},
          ],
          bxhj: [
            { required: true, message: '请输入本息合计!'},
          ],
        },
        url: {
          add: "/cdCredrightsInf/cdCredrightsInf/add",
          edit: "/cdCredrightsInf/cdCredrightsInf/edit",
          queryById: "/cdCredrightsInf/cdCredrightsInf/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }
         
        })
      },
    }
  }
</script>